import org.cicd.enums.BuildType
import org.cicd.modle.AppInfoVars
import org.cicd.utils.utils

def call(appMap) {
        def utils = new utils()
        utils.printMessage("获取项目参数", "green")
        def appInfo = new AppInfoVars()
        def pomPath = "${workspace}"+utils.getFileSeparator()+"pom.xml";
        def packagePath = "${workspace}"+utils.getFileSeparator()+"package.json"
        def deployPropertiesPath =  "${workspace}"+utils.getFileSeparator()+"deploy.properties"


        def buildUser = getBuildUser()
        appInfo.BUILD_USER = buildUser
        appInfo.repositoryUrl = utils.getGitRepUrl()

        boolean isMvn = utils.fileExist(pomPath)
        boolean isNpm = utils.fileExist(packagePath)
        if(isMvn) {
                def pom = utils.loadMavenPom(pomPath)
                appInfo.appId = "${pom.artifactId}"
                appInfo.appName = "${pom.artifactId}"
                appInfo.appVersion = "${pom.version}"
                appInfo.buildType = BuildType.MVN
        } else if (isNpm){
                def prop = utils.loadJson(packagePath)
                appInfo.appId = "${prop.name}"
                appInfo.appName = "${prop.name}"
                appInfo.appVersion = "${prop.version}"
                appInfo.buildType = BuildType.NPM
        }

        boolean needPackage = utils.fileExist(deployPropertiesPath)
        appInfo.needPackage = needPackage
        if(needPackage) {
             def deploy_properties = utils.loadProperties(deployPropertiesPath)
             if(null==deploy_properties) {
                utils.printErrorMessage("项目根目录 下 deploy.properties 文件 配置缺失，请填写正确的信息，格式如: {分支名称}={dev|test|staging}, 例子:feature/1.0.0=dev, release/1.0=test","red")
                return
             }
             def deployBranch = "dev"
             def deployEnvNames = "dev"
             deploy_properties.each {
                 deployBranch = it.key
                 deployEnvNames = it.value
             }
            appInfo.branchName = deployBranch
            appInfo.deployEnvNames = deployEnvNames.split(",")
            if(appInfo.branchName !="${env.BRANCH_NAME}") {
                utils.printErrorMessage("项目根目录 下 deploy.properties 文件 配置 和 分支名称 不一致 ")
            }
        }

        return appInfo;
}

return this